package com.attendance.www.hr.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.ISystemConfigureService;
import com.zhangkongli.frame.core.ResultMap;

/**
 * 班次设置
 * @author
 * 2017-10-10
 *
 */
@Controller
@RequestMapping("/systemConfigure")
public class SystemConfigureController {
	@Resource
	private ISystemConfigureService systemConfigureService;
	
	@RequestMapping(value = "/getEffectiveDate.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object getEffectiveDate(HttpServletRequest request) {
		return ResultMap.success(systemConfigureService.getEffectiveDate());
	}

	/**
	 * 获取配置表里，接收邮件的邮箱地址
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getEmail.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object getEmail(HttpServletRequest request) {
		return ResultMap.success(systemConfigureService.getEmail());
	}
	
	/**
	 * 更新接收者邮箱
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/updateEmail.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object updateEmail(HttpServletRequest request) {
		String emailAddress = request.getParameter("emailAddress");
		String emailPassword = request.getParameter("emailPassword");
		if (StringUtils.isBlank(emailAddress)) {
			throw new ResultFaultException("0_00001");
		}
		return ResultMap.success(systemConfigureService.updateEmail(emailAddress,emailPassword));
	}
	
}
